<?php
namespace app\shop\model;

use think\Db;

class StaffTag extends \ShopModel
{
    protected $table = 'sh_crm_staff_tag_relevance';

    public function StaffTagDb(){
        return Db::name('crm_staff_tag_relevance');
    }

    //标签列表
    public function tagList($params){
        $where = [];
        if(!empty($params['query'])){
            $where['tag_name'] = ['like','%'.$params['query'].'%'];
        }
        
        $data =  Db::name('tag')->where($where)->field('tag_id,tag_name')->select();
        foreach($data as &$v){
            $v['is_checked'] = false;
        }
        return $data;
    }

    //添加标签
    public function add($params){
        Db::name('tag')->insert($params);
        return true;
    }

    //标签重命名
    public function rename($params){
        Db::name('tag')->where('tag_id',$params['tag_id'])->update(['tag_name'=>$params['tag_name']]);
        return true;
    }

    //删除标签
    public function del_tag($id){
        Db::name('tag')->where('tag_id',$id)->delete();
    }

}